/**
 * Zhznet.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.liwei.httpclient.util;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;

/**
 *
 * @author Liwei
 * @version $Id: CookieUtil.java, v 0.1 2011-1-22 上午11:04:23 Liwei Exp $
 */
public class CookieUtil {
    /**
     *
     * @param LOGON_SITE    服务器
     * @param SITE          web应用
     * @param LOGON_PORT    端口
     * @param client        HttpClient
     */
    public static void getCookie(String LOGON_SITE, String SITE, int LOGON_PORT, HttpClient client) {
        // 查看 cookie 信息
        CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
        Cookie[] cookies = cookiespec.match(LOGON_SITE, LOGON_PORT, SITE, false, client.getState()
            .getCookies());
        if (cookies.length == 0) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.length; i++) {
                System.out.println(cookies[i].toString());
            }
        }
    }
}
